;
$(function() {
    var tabs = $("#mbEdiet_menu_tabs").tabs();
    //
    //tabs.find( ".ui-tabs-nav" ).sortable({
    //  axis: "x",
    //  stop: function() {
    //    tabs.tabs( "refresh" );//刷新
    //  }
    //});
    //
});

//-----------------panel-heading-OpenClose--------
$(function() {
    $(document).on('click', '.panel-heading-OpenClose',
    function() {
        var dt = $(this);
        var dl = $(this).parent();
        if (dl.hasClass('open')) {
            dl.removeClass('open');
        } else {
            dl.addClass('open');
        }
    });
});
//-----------------panel-heading-OpenClose--------end

//--------保存模板--------
$(function() {

    var $btn = $('#mbSave');
    var url = $btn.data('ajaxUrl');
    var lock = false;
	
	var _getMBID = function() {
        return  MB.MBID || 0 ;
    }
	
    var _getBMSET = function() {
        return $('#BMSET').data('json');
    }
    var _getSSMB1 = function() {
        var d = new Array();
        $('#SSMB1').find('.field').each(function() {
            try {
                var j = $(this).data('json');

                d.push(j);
            } catch(e) {
                console.log(e);
            }
        });
        return d;
    }
	var _getSSMB2 = function() {
        var d = new Array();
        $('#SSMB2').find('.field').each(function() {
            try {
                var j = $(this).data('json');

                d.push(j);
            } catch(e) {
                console.log(e);
            }
        });
        return d;
    }

    //点击【保存模板】	
    $btn.on('click',
    function() {
        var url = $(this).data('ajaxUrl');
        console.log($(this).data());
        //获取数据
        var MB = {};
        MB.MBID = _getMBID();
        MB.BMSET = _getBMSET();
		MB.SSMB1 = _getSSMB1();
		MB.SSMB2 = _getSSMB2();
		MB.ai = F.j.ai;
        console.log('保存模板json', MB);
        //return false;
        //上锁
        if (lock) {
            return false;
        } else {
            lock = true;
        }
        console.log('测试：', JSON.stringify(MB) );
        $.ajax({
            url: url,
            type: "POST",
            data: MB,
            dataType: "json",
            success: function(msg) {
                alert('ok 保存成功！！！');
                lock = false;
            },
            error: function(e) {
                console.log('保存表单-ajax错误:', e);
                lock = false;
            }

        });
    });

});
//--------保存模板--------end
$(function() {
    //排序
    $(".widgets-sortables").sortable({
		connectWith: ".widgets-sortables",											 
        placeholder: "widget-placeholder",
        //占位符
        helper: "clone", appendTo: "body",
        cursor: "move",
        zIndex: 9999,
        //axis: "y",
        //revert: true,
        //items: "div:not(.ui-state-disabled)", //不排序
        items: "div.field",
        //只有 div.field 参与排序
        start: function(e, ui) {
            //拖动块
            var h = ui.helper.outerHeight();
            //滚动占位符 - 占位符高度 = widget-body 高度
            $('.ui-sortable-placeholder').css("height", h);
        },
        stop: function(e, ui) {
            ui.item.attr('style', '');
        }
    });

    //拖动
    $(".widget-list").children(".widget-list-btn").draggable({
        connectToSortable: ".widgets-sortables",
        appendTo: "body",
        helper: "clone",
        zIndex: 9999,
        revert: "invalid",// invalid  |  valid
        //放进去 拿不出来
        start: function(a, b, c, d) {
            //$(this).addClass('ui-state-highlight');
			//--------------lrxin ------------2016-11-07 -------
			if( $(this).hasClass('disabled') ){
				var text = $(this).find('.widget-title-txt').text();
				alert('联系信息字段【'+text+'】已经存在，不可以重复添加！！！');	
				return false;
			}
			//--------------lrxin ------------2016-11-07 -------end

        },
        drag: function(a, b, c, d) {},
        stop: function(a, b, c, d) {



			
            //$(this).removeClass('ui-state-highlight');
            var $b = $(this);
            //获取 字段类型 
            var fieldType = $b.data('fieldType');
            var $f = $('<div class="field field_' + fieldType + ' ">' + html + '</div>');
            //默认数据
            var j = $.extend( {} , F.j[fieldType] );
				if( j.fieldCate != 2 ){
					j.name = F._getNewName();
				}
            //读取模版	
            var tpl = template($('#' + j.fieldType + '_show_template').html());
            var html = $(tpl(j));
            //渲染模板 追加数据
            $f.data('json', j).html(html);
            //替换
            $('.widgets-sortables').find('.ui-draggable-dragging').replaceWith($f);
            //$f.click();
			F._linkGroup_disabled();
			niceScrollresize();
        },
    }).disableSelection();

    // hover
    $(".widgets-sortables").on('mouseenter', '.field', function() {
        $(this).addClass('hover');
    }).on('mouseleave', '.field', function() {
        $(this).removeClass('hover');
    }).on('click', '.field',  function() {
        $(".widgets-sortables").find('.field').removeClass('edit');
        $(this).addClass('edit');
        //修改 字段 this = field
        F._edit(this); //----------------------------------------
    });
    //--？？？？？？？？？？？？？？---------------------------这里还有些问题----------------
    $(document).on("click", 'body',
    function(e) {
        var target = $(e.target);
        if (target.closest(".field").length == 0) {
            //$(".field ").removeClass('edit');
        }
    });

    //挂件 删除 
    $(".widgets-sortables").on('click', '.field-btn-del',
    function() {
		if(!confirm("确定要删除吗？")){return;}
        $(this).parents('.field').remove();
		$('#mbEdiet_panel').empty();
		F._linkGroup_disabled();
		niceScrollresize();
		$('#ui-id-2').click();
    });
    //挂件 复制 
    $(".widgets-sortables").on('click', '.field-btn-copy',
    function() {
		var $f = $(this).parents('.field');
		//-------------判断禁止复制-----------
		var j = $f.data('json');
		if(j.fieldCate == 2){alert('联系人信息，禁止复制！！！');return ;};
		

		//-------------判断禁止复制-----------end
//-----------------这里的复制不是最新的 -------------------------------
        $f2 = $f.clone(true).insertAfter($f);
		var j = $f2.data('json');
		if( j.fieldCate != 2 ){
			j.name = F._getNewName();
		}
		$f2.data('json',j);
		niceScrollresize();
    });

});

//定义全局变量JS (竞赛)
var JS = JS || {};

var F = F || {};
F.MB = MB || {};
//console.log(F.MB);

F._init = function() {
	F.BMSET._init();
	F._show();
};


F.BMSET = {
	data:{
		app_name:'',
		is_allow_update:true,
		is_btime:true,
		btime:'',
		is_etime:true,
		etime:''

		
		
	},
	_init: function(){
		this._show();
	},
	_show: function(){
		var j = $.extend( {} , F.BMSET.data, MB.BMSET );
        //读取模版	
        var tpl = template($('#BMSET_template').html());
        var html = $(tpl(j));
		$('#BMSET').data('json', j).html(html);
		
		html.find('[dateRangePicker=date]').each(function(){
			$(this).dateRangePicker(
			{
				autoClose: true,
				singleDate : true,
				showShortcuts: false,
				singleMonth: true,
				setValue: function(s)
				{
					if( s != $(this).val())
					{
						$(this).val(s).change();
					}
				}
			});
		})
		html.find('[dateRangePicker=datetime]').each(function(){
			$(this).dateRangePicker(
			{
				autoClose: true,
				singleDate : true, //单日期模式
				format: 'YYYY-MM-DD HH:mm:ss',
				showShortcuts: false,
				singleMonth: true, //显示一个月
				time: {
					enabled: true,
				},
				setValue: function(s)
				{
					if( s != $(this).val())
					{
						$(this).val(s).change();
					}
				}
			});
		})
		

		
		
		
		
		//更新值
		html.on('change','[name]',function(){
			j.app_name = html.find('[name=app_name]').val();
			
			j.is_allow_update = (html.find('[name=is_allow_update]').is(':checked') ) ? true : false;
			j.is_btime = ( html.find('[name=is_btime]').is(':checked') ) ? true : false;
			j.btime = html.find('[name=btime]').val();

			j.is_etime = ( html.find('[name=is_etime]').is(':checked') ) ? true : false;
			j.etime = html.find('[name=etime]').val();



		});
		var lock = false;
		html.on('click','#BMset_btn_save',function(){
			var ajaxUrl = $(this).attr('ajaxUrl');
			if( lock ){ return false ;}else{ lock = true ;}
			$.ajax({
				url : ajaxUrl,
				type: 'post',
				data: j,
				dataType: 'json',
				success:function(d){
					alert('ajax');
					console.log(d);
					if(d.ret == 0 ){
						alert('保存设置成功');
						//window.location.href = '';
					}else{
						alert(d.msg);
						lock = false;
					}
					
				}
			});
		});
		
	},
	
	
}

//-- json 数据
F.j = {};
F.j.ai = MB.ai || 0;
//--单行文本输入框
F.j.TextField = {
    fieldType: 'TextField',
	fieldCate:1,    //fieldCate 1.通用字段  2.联系人字段
	is_def:false,   //是否默认字段  true默认字段 不可删除和复制    false 可以复制和删除
    title: '标题文字',
    value: '默认值',
    note: '我是描述',
    required: 1,
    is_minlength: 0,
    minlength: 5,
    is_maxlength: 0,
    maxlength: 10
};
//--多行文本输入框
F.j.TextArea = {
    fieldType: 'TextArea',
	fieldCate:1,
	is_def:false,
    title: '多行文本',
    value: '',
    note: '',
    required: 1,
    is_minlength: 0,
    minlength: 5,
    is_maxlength: 0,
    maxlength: 10
};
//--密码框
F.j.PassWord = {
    fieldType: 'PassWord',
	fieldCate:1,
	is_def:false,
    title: '密码输入',
    value: '',
    note: '',
    required: 1,
    is_minlength: 0,
    minlength: 5,
    is_maxlength: 0,
    maxlength: 10
};
//--日期时间
F.j.DateTime = {
    fieldType: 'DateTime',
	fieldCate:1,
	is_def:false,
    title: '日期时间',
    value: '',
    note: '',
    required: 1,
    type: 'datetime',    // datetime  | date | time

};
//--描述
F.j.TextDesc = {
    fieldType: 'TextDesc',
	fieldCate:1,
	is_def:false,
    title: '标题文字',
    note: '请在右侧面板添加段落说明',
    hr: 1
};
//--单选按钮组
F.j.Radio = {
    fieldType: 'Radio',
	fieldCate:1,
	is_def:false,
    title: '标题文字',
    note: '',
	required: 1,
	ai: 3,
    item:[
		  {title:'选项1',value:'1',is_checked:false},
		  {title:'选项2',value:'2',is_checked:false},
		  {title:'选项3',value:'3',is_checked:false}
		 ]
};
//--多选按钮组
F.j.CheckBox = {
    fieldType: 'CheckBox',
	fieldCate:1,
	is_def:false,
    title: '标题文字',
    note: '',
	required: 1,
	ai: 3,
    item:[
		  {title:'选项1',name:'1',value:'1',is_checked:false},
		  {title:'选项2',name:'2',value:'2',is_checked:false},
		  {title:'选项3',name:'3',value:'3',is_checked:false}
		 ]
};
//--下拉菜单
F.j.Select = {
    fieldType: 'Select',
	fieldCate:1,
	is_def:false,
    title: '下拉菜单',
    note: '',
	required: 1,
	ai: 3,
    item:[
		  {title:'选项1',value:'1',is_checked:false},
		  {title:'选项2',value:'2',is_checked:false},
		  {title:'选项3',value:'3',is_checked:false}
		 ]
};
//--上传图片
F.j.UploadPic = {
    fieldType: 'UploadPic',
	fieldCate:1,
	is_def:false,
    title: '上传图片',
    // value: '',
    note: '',
    required: 1,
	uploadtype:1 , // 1上传一张  |  2上传多张
    minlength: 1,
    maxlength: 5
};
//--上传图片
F.j.UploadFile = {
    fieldType: 'UploadFile',
	fieldCate:1,
	is_def:false,
    title: '上传文件',
    // value: '',
    note: '',
    required: 1,
	uploadtype:1 , // 1上传一张  |  2上传多张
    minlength: 1,
    maxlength: 5
};
//---------------------联系人 字段--------------------

//--姓名
F.j.LinkName = {
    fieldType: 'LinkName',
	fieldCate:2,    //fieldCate 1.通用字段  2.联系人字段
	is_def:false,   //是否默认字段  true默认字段 不可删除和复制    false 可以复制和删除
    title: '姓名',
	name:'name',
    value: '',
    note: '',
    required: 1,
	is_minlength: 0,
    minlength: 5,
    is_maxlength: 0,
    maxlength: 10
};
//--手机号
F.j.LinkPhone = {
    fieldType: 'LinkPhone',
	fieldCate:2,    //fieldCate 1.通用字段  2.联系人字段
	is_def:false,   //是否默认字段  true默认字段 不可删除和复制    false 可以复制和删除
    title: '手机号',
	name:'mobile',
    value: '',
    note: '',
    required: 1,
};
//--邮箱
F.j.LinkEmail = {
    fieldType: 'LinkEmail',
	fieldCate:2,    //fieldCate 1.通用字段  2.联系人字段
	is_def:false,   //是否默认字段  true默认字段 不可删除和复制    false 可以复制和删除
    title: '邮箱',
	name:'email',
    value: '',
    note: '',
    required: 1,
};
//--地址
F.j.LinkAddress = {
    fieldType: 'LinkAddress',
	fieldCate:2,    //fieldCate 1.通用字段  2.联系人字段
	is_def:false,   //是否默认字段  true默认字段 不可删除和复制    false 可以复制和删除
    title: '地址',
	name:'address',
    value: '',
    note: '',
    required: 1,
};
//--电话
F.j.LinkTel = {
    fieldType: 'LinkTel',
	fieldCate:2,    //fieldCate 1.通用字段  2.联系人字段
	is_def:false,   //是否默认字段  true默认字段 不可删除和复制    false 可以复制和删除
    title: '电话',
	name:'tel',
    value: '',
    note: '',
    required: 1,
};





F._getNewName=function(){
	F.j.ai++;
	return 'n'+F.j.ai;
}
// 页面进来 初始化 现有 模板 json
F._show = function() {
	var SSMB1 = $.extend({},F.MB.SSMB1); 
	$.each(SSMB1,function(){
		var j = this;
		var tpl = template($('#' + j.fieldType + '_show_template').html());
   		var html = $(tpl(j));
		var $f = $('<div class="field field_' + j.fieldType + ' ">' + html + '</div>');
		$f.html(html).data('json',j);
		$('#SSMB1').append($f);
		
	});
	var SSMB2 = $.extend({},F.MB.SSMB1); 
	$.each(SSMB2,function(){
		var j = this;
		var tpl = template($('#' + j.fieldType + '_show_template').html());
   		var html = $(tpl(j));
		var $f = $('<div class="field field_' + j.fieldType + ' ">' + html + '</div>');
		$f.html(html).data('json',j);
		$('#SSMB2').append($f);
		
	});
	
	F._linkGroup_disabled();
	

};
//点击 字段 进入编辑模式
F._edit = function(f) {

    var $f = $(f); //当前编辑的对象 field 
    var j = $.extend( {} , $f.data('json') );
	

	if( isEmptyObject(j) ){return };// 空返回

    var tpl = template($('#' + j.fieldType + '_edit_template').html());
    var html = $(tpl(j));
    var _updata = function() {
        var tpl = template($('#' + j.fieldType + '_show_template').html());
        var html = $(tpl(j));
		console.log('修改json',j);
        $f.data('json', j).html(html);
        //$f.attr('json', JSON.stringify(j));
		niceScrollresize();
		
    }
	//单选
	var e_radio = function(html){
		if( 'Radio' != j.fieldType){return ;}
		var html = html ;
		var items = html.find('.form-group-items');
		
		//更新 radio数据
		var _radioUpdate = function(){
			var arr = new Array;
			items.find('.form-group-item:not(".deleted")').each(function(){
				var that = $(this);
				var j = {}
				j.title = that.find('.fe-text').val();
				j.value = that.find('.fe-radio').val();;
				j.is_checked = ( that.find('.fe-radio').is(':checked') ) ? true : false;
				arr.push(j);
			});
			j.item = arr;
			console.log(j);
			_updata();	
		
		};
		//加号位置
		var _btn_add_place = function(){
				var btn_add = html.find('.fe-item-add');
				var xx = items.find('.form-group-item:not(.deleted)');
				if( xx.length > 0 ){
					xx.last().append(btn_add);
				}else{
					items.append(btn_add);
				}
			}
		_btn_add_place();
		//cancel
		var _checked_cancel = function(){
				html.on('click','.btn-radio-checked-cancel',function(){
					items.find('.fe-radio').attr("checked",false);
					_radioUpdate();
				});
			}
		_checked_cancel();
		var _radio_new_ai = function(){
			return ++j.ai;	
		};
		//修改
		items.on('keyup change','input ',function(){
			_radioUpdate();
		})
		//删除
		items.on('click','.fe-item-del', function(){
			$(this)
			.closest('.form-group-item')
			.css('background','#999').addClass('deleted')
			.fadeOut(function(){ _radioUpdate(); _btn_add_place();});	
			

		});
		//添加
		items.on('click','.fe-item-add', function(){
				var new_item_json = {title:'选项',value:'1',is_checked:false};
				var i = _radio_new_ai();
				new_item_json.title += i;
				new_item_json.value = i;
				
			    var tpl = template($('#' + j.fieldType + '_edit_item_template').html());
   				var item = $(tpl(new_item_json));
				items.append(item);
				_radioUpdate();
				_btn_add_place();
				

		});

		
		
		
	}
	
	//多选
	var e_checkbox = function(html){
		//console.log('看看：',j);
		if( 'CheckBox' != j.fieldType){return ;}
		var html = html ;
		var items = html.find('.form-group-items');
		
		//更新 radio数据
		var _radioUpdate = function(){
			var arr = new Array;
			items.find('.form-group-item:not(".deleted")').each(function(){
				var that = $(this);
				var j = {}
				j.title = that.find('.fe-text').val();
				j.value = that.find('.fe-radio').val();;
				j.is_checked = ( that.find('.fe-radio').is(':checked') ) ? true : false;
				arr.push(j);
			});
			j.item = arr;
			console.log(j);
			_updata();	
		
		};
		//加号位置
		var _btn_add_place = function(){
				var btn_add = html.find('.fe-item-add');
				var xx = items.find('.form-group-item:not(.deleted)');
				if( xx.length > 0 ){
					xx.last().append(btn_add);
				}else{
					items.append(btn_add);
				}
			}
		_btn_add_place();
		//cancel
		var _checked_cancel = function(){
				html.on('click','.btn-radio-checked-cancel',function(){
					items.find('.fe-radio').attr("checked",false);
					_radioUpdate();
				});
			}
		_checked_cancel();
		var _radio_new_ai = function(){
			return ++j.ai;	
		};
		//修改
		items.on('keyup change','input ',function(){
			_radioUpdate();
		})
		//删除
		items.on('click','.fe-item-del', function(){
			$(this)
			.closest('.form-group-item')
			.css('background','#999').addClass('deleted')
			.fadeOut(function(){ _radioUpdate(); _btn_add_place();});	
			

		});
		//添加
		items.on('click','.fe-item-add', function(){
				var new_item_json = {title:'选项',value:'1',is_checked:false};
				var i = _radio_new_ai();
				new_item_json.title += i;
				new_item_json.value = i;
				
			    var tpl = template($('#' + j.fieldType + '_edit_item_template').html());
   				var item = $(tpl(new_item_json));
				items.append(item);
				_radioUpdate();
				_btn_add_place();
				

		});

		
		
		
	}
	
	//下拉菜单
	var e_select = function(html){
		if( 'Select' != j.fieldType){return ;}
		var html = html ;
		var items = html.find('.form-group-items');
		
		//更新 radio数据
		var _radioUpdate = function(){
			var arr = new Array;
			items.find('.form-group-item:not(".deleted")').each(function(){
				var that = $(this);
				var j = {}
				j.title = that.find('.fe-text').val();
				j.value = that.find('.fe-radio').val();;
				j.is_checked = ( that.find('.fe-radio').is(':checked') ) ? true : false;
				arr.push(j);
			});
			j.item = arr;
			_updata();	
		
		};
		//加号位置
		var _btn_add_place = function(){
				var btn_add = html.find('.fe-item-add');
				var xx = items.find('.form-group-item:not(.deleted)');
				if( xx.length > 0 ){
					xx.last().append(btn_add);
				}else{
					items.append(btn_add);
				}
			}
		_btn_add_place();
		//cancel
		var _checked_cancel = function(){
				html.on('click','.btn-radio-checked-cancel',function(){
					items.find('.fe-radio').attr("checked",false);
					_radioUpdate();
				});
			}
		_checked_cancel();
		var _radio_new_ai = function(){
			return ++j.ai;	
		};
		//修改
		items.on('keyup change','input ',function(){
			_radioUpdate();
		})
		//删除
		items.on('click','.fe-item-del', function(){
			$(this)
			.closest('.form-group-item')
			.css('background','#999').addClass('deleted')
			.fadeOut(function(){ _radioUpdate(); _btn_add_place();});	
			

		});
		//添加
		items.on('click','.fe-item-add', function(){
				var new_item_json = {title:'选项',value:'1',is_checked:false};
				var i = _radio_new_ai();
				new_item_json.title += i;
				new_item_json.value = i;
				
			    var tpl = template($('#' + j.fieldType + '_edit_item_template').html());
   				var item = $(tpl(new_item_json));
				items.append(item);
				_radioUpdate();
				_btn_add_place();
				

		});

		
		
		
	}
	//日期时间
	var e_datetime = function(html){
		if( 'DateTime' != j.fieldType){return ;}
		var html = html ;
		html.on('change','[name=type]',function(){
			j.type = 	$(this).val();
			
			_updata();	
		});
		
	};
	e_datetime(html);
	
	

    $('#mbEdiet_panel').html(html);

    //追加给 class="kindeditor" 
    html.find('.kindeditor').each(function() {
        var $textarea = $(this);
        editor = KindEditor.create($textarea, {
            items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'link', 'unlink'],
            width: '100%',
            //height: '100px',
            themeType: 'simple',
            //皮肤
            resizeType: 1,
            //2或1或0，2时可以拖动改变宽度和高度，1时只能改变高度，0时不能拖动。
            allowFileManager: false,
            //afterBlur: function () { this.sync(); $textarea.change();} ,
            afterChange: function() {
                this.sync();
                $textarea.change();
            }
        });
    });
    //追加给 class="kindeditor" ----end----------------
	
	

    //修改 标题
    html.find('#fe-title').on('keyup change',
    function() {
        j.title = $(this).val();
        _updata();
    });
    // 修改描述
    html.find('#fe-note').on('change',
    function() {
        j.note = $(this).val();
        _updata();
    });
    // 修改默认值
    html.find('#fe-value').on('keyup change',
    function() {
        j.value = $(this).val();
        _updata();
    });
    // 必填
    html.find('#fe-required').on('change',
    function() {
        j.required = ($(this).is(':checked')) ? $(this).val() : 0;
        _updata();
    });
    // isminlength
    html.find('#fe-is_minlength').on('change',
    function() {
        j.is_minlength = ($(this).is(':checked')) ? $(this).val() : 0;
        _updata();
    });
    // ismaxlength
    html.find('#fe-is_maxlength').on('change',
    function() {
        j.is_maxlength = ($(this).is(':checked')) ? $(this).val() : 0;
        _updata();
    });
    // minlength
    html.find('#fe-minlength').on('keyup change',
    function() {
        j.minlength = $(this).val();
        _updata();
    });
    // maxlength
    html.find('#fe-maxlength').on('keyup change',
    function() {
        j.maxlength = $(this).val();
        _updata();
    });
	// fe-radio-uploadtypeh
	html.find('[name=fe-radio-uploadtype]').on('change',
    function() {
        j.uploadtype = $(this).val();
        _updata();
    });

    //修改 hr
    html.find('#fe-br').on('change',
    function() {
        j.hr = ($(this).is(':checked')) ? $(this).val() : 0;
        _updata();

    });
    // 修改富文本
    html.find('#fe-info').on('change',
    function() {
        j.info = $(this).val();
        _updata();
    });
	
	
	//修改单选按钮组
	e_radio(html);
	
	//多选
	e_checkbox(html);
	
	//下拉菜单
	e_select(html);

    $('#ui-id-3').click();
};


F._linkGroup_disabled =function(){
	var _getSSMB1 = function() {
        var d = new Array();
        $('#SSMB1').find('.field').each(function() {
            try {
                var j = $(this).data('json');
                d.push(j);
            }catch(e) {console.log(e);}
        });
        return d;
    }
	var _getSSMB2 = function() {
        var d = new Array();
        $('#SSMB2').find('.field').each(function() {
            try {
                var j = $(this).data('json');
                d.push(j);
            } catch(e) {console.log(e);}
        });
        return d;
    }
	$('[data-field-type]','.Link-list').removeClass('disabled');
	
	$.each(_getSSMB1(),function(){
		var j = this;
		$('[data-field-type='+j.fieldType+']','.Link-list').addClass('disabled');
	});
	$.each(_getSSMB2(),function(){
		var j = this;
		$('[data-field-type='+j.fieldType+']','.Link-list').addClass('disabled');
	});
	
}//end F._linkGroup_disabled =function(){
$(function() {
    F._init();
});





//----------------------
function fix(num, length) {
  return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num;
}

//-----------------------------------------
function isEmptyObject(e) {  
    var t;  
    for (t in e)  
        return !1;  
    return !0  
}  